
from pluginHelper import *
import re

ro = re.compile(r"""#ifndef\s+(?P<sym>\S*)
#define\s+(?P=sym)""", re.MULTILINE| re.DOTALL)

SEVERITY = 2

#
# This is a scanner function that can scan the file line-by-line.
# The function is called once for each line in the input file. THe filename
# and current line number is passed to the function. The function returns
# a boolean value indicating whether it wants more input (True), or whether
# it does not care any moer about this file (False).
#
# errors are reported using reportError(line, col)
#
def scanFile(self, filePath):
	if filePath[-2:].lower() == '.h':
		data = open(filePath).read()
		so = ro.search(data)
		if not so:
			reportError(1, SEVERITY)
	#
	# Assume that each loop starts on a new line:
	return True


#
# Describe the plugin:
if __name__ == "__main__":
	init()
	describePlugin('includeguard','scanner', 'Ensures that all header files are protected by an include guard.', False)

	#
	# Set the scan function, along with it's type:
	setScanFunction(SCANNER_TYPE_FILE_PATH, scanFile)


